import React, { Component } from 'react'
import moment from 'moment'
export default class TimeCom extends Component {
    state = {
        nowTime:moment().format('YYYY-MM-DD HH:mm:ss')
    }
    componentDidMount(){
        console.log('this: ',this)
        this.timer = setInterval(()=>{
            console.log(1)
            this.setState({
                nowTime:moment().format('YYYY-MM-DD HH:mm:ss')
            })
        },1000)
    }

    componentWillUnmount(){
        clearInterval(this.timer)
    }
    render() {
        let {nowTime} = this.state
        return (
            <div>
                <p>当前时间是：{nowTime}</p>
            </div>
        )
    }

}
